"""
RPA服务配置文件
"""
import os
from typing import Optional
from pydantic_settings import BaseSettings
from pydantic import field_validator


class Settings(BaseSettings):
    """应用配置"""
    
    # 应用基础配置
    app_name: str = "RPA Service"
    debug: bool = False
    
    # 数据库配置
    database_url: str = "mysql+asyncmy://root:fuzong1008!@118.178.197.146:3306/overseas_rpa"
    
    # 浏览器配置
    chrome_timeout: int = 300  # 5分钟
    login_timeout: int = 600   # 10分钟
    page_load_timeout: int = 30
    
    # 代理配置
    proxy_enabled: bool = False
    proxy_host: Optional[str] = None
    proxy_port: Optional[int] = None
    proxy_username: Optional[str] = None
    proxy_password: Optional[str] = None
    
    # 日志配置
    log_level: str = "INFO"
    log_file: str = "logs/rpa_service.log"
    log_rotation: str = "1 day"
    log_retention: str = "30 days"
    
    # WebSocket配置
    websocket_port: int = 8765
    
    # Cookie存储路径
    cookie_storage_path: str = "data/cookies"
    
    # 数据存储路径
    data_storage_path: str = "data/storage"
    
    @field_validator('proxy_port', mode='before')
    @classmethod
    def validate_proxy_port(cls, v):
        if v == '' or v is None:
            return None
        return int(v)
    
    class Config:
        env_file = ".env"
        env_file_encoding = "utf-8"


# 全局配置实例
settings = Settings()
